import React, { Component } from 'react'
import { getRecommendArticle } from '@/services/common'
import { Icon, List, Tooltip } from 'antd'
import { history, Link } from 'umi'

import './index.less'
export default class index extends Component {
  state = {
    hotArticle: [],
    currentArticle: [],
  }
  componentDidMount() {
    this.getRecommendArticle()
  }
  getRecommendArticle = async () => {
    const { data: hotArticle } = await getRecommendArticle('view_count')
    const { data: currentArticle } = await getRecommendArticle('add_time')
    this.setState({ hotArticle, currentArticle })
  }
  render() {
    const { hotArticle, currentArticle } = this.state
    return (
      <div>
        {/* 热门文章 */}
        <div className="recommend-div">
          <List
            header={
              <div>
                热门文章推荐 <Icon type="fire" theme="filled" style={{ color: 'red' }} />
              </div>
            }
            bordered
            dataSource={hotArticle}
            renderItem={(item, index) => (
              <List.Item>
                <Link to={{ pathname: '/detail/' + item.id }}>
                  <Tooltip title={index + 1 + '. ' + item.title} placement="bottom">
                    {index + 1}. {item.title}
                  </Tooltip>
                </Link>
              </List.Item>
            )}
          />
        </div>
        {/* 最新发布 */}
        <div className="recommend-div">
          <List
            header={
              <div style={{ color: 'rgb(43, 204, 43)' }}>
                最新发布&nbsp;
                <Icon type="plus-square" theme="filled" />
              </div>
            }
            bordered
            dataSource={currentArticle}
            renderItem={(item, index) => (
              <List.Item>
                <Link to={{ pathname: '/detail/' + item.id }}>
                  <Tooltip title={index + 1 + '. ' + item.title} placement="bottom">
                    {index + 1}. {item.title}
                  </Tooltip>
                </Link>
              </List.Item>
            )}
          />
        </div>
      </div>
    )
  }
}
